/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ZDloader;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout;
import javax.swing.JProgressBar;
import javax.swing.LayoutStyle.ComponentPlacement;

import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Color;



/**
 *
 * @author lanarenauser
 */
public class Gui extends javax.swing.JFrame {
        
        private Image image;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    public static javax.swing.JProgressBar jProgressBar1;
    public static JLabel OverAll;

    /**
     * Creates new form Gui
     */
    public Gui(String e){}
    
    public Gui() {
        initComponents();
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
                        
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel1.addComponentListener(new ComponentAdapter() {
                @Override
                public void componentResized(ComponentEvent arg0) {
                }
        });
        jPanel2 = new javax.swing.JPanel();
        jProgressBar1 = new JProgressBar(0,100);;
        jProgressBar1.setStringPainted(true);
        
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1Layout.setHorizontalGroup(
        	jPanel1Layout.createParallelGroup(Alignment.LEADING)
        		.addGap(0, 600, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
        	jPanel1Layout.createParallelGroup(Alignment.LEADING)
        		.addGap(0, 290, Short.MAX_VALUE)
        );
        jPanel1.setLayout(jPanel1Layout);

        jButton1.setText("Cancel");
        
        OverAll = new JLabel("Test");
        OverAll.setBackground(Color.RED);
        OverAll.setDoubleBuffered(true);
        OverAll.setVerticalAlignment(SwingConstants.BOTTOM);
        OverAll.repaint();
        
        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2Layout.setHorizontalGroup(
        	jPanel2Layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(jPanel2Layout.createSequentialGroup()
        			.addContainerGap()
        			.addGroup(jPanel2Layout.createParallelGroup(Alignment.LEADING)
        				.addGroup(jPanel2Layout.createSequentialGroup()
        					.addComponent(jProgressBar1, GroupLayout.PREFERRED_SIZE, 483, GroupLayout.PREFERRED_SIZE)
        					.addPreferredGap(ComponentPlacement.UNRELATED)
        					.addComponent(jButton1, GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE))
        				.addComponent(OverAll, GroupLayout.PREFERRED_SIZE, 177, GroupLayout.PREFERRED_SIZE))
        			.addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
        	jPanel2Layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(jPanel2Layout.createSequentialGroup()
        			.addGap(23)
        			.addGroup(jPanel2Layout.createParallelGroup(Alignment.LEADING, false)
        				.addComponent(jProgressBar1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        				.addComponent(jButton1, GroupLayout.DEFAULT_SIZE, 38, Short.MAX_VALUE))
        			.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        			.addComponent(OverAll)
        			.addContainerGap())
        );
        jPanel2.setLayout(jPanel2Layout);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        layout.setHorizontalGroup(
                layout.createParallelGroup(Alignment.LEADING)
                        .addComponent(jPanel1, GroupLayout.PREFERRED_SIZE, 600, GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPanel2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        );
        getContentPane().setLayout(layout);
        
        JLayeredPane pane = new JLayeredPane();
        //Pack Gui panel elemets
        //todo:Not using
        pane.add(jPanel1, 1, 0);
        pane.add(jPanel2, 1, 0);
        pack();
    }
    
    public void loadImage(String imageURL){
        try{
        	
        		//Image Path [given in Dbconnect]
                //todo: ./build/ is a custom hard coded path remove to get full dir directly from main.mdb
                this.image = new ImageIcon("./build/" + imageURL).getImage();
                Dimension size = new Dimension(image.getWidth(null), image.getHeight(null));
                jPanel1.setPreferredSize(size);
                jPanel1.setMaximumSize(size);
                jPanel1.setMinimumSize(size);
        }catch(SecurityException e){
                //If media file was not found
                JOptionPane.showMessageDialog(null, "Media File Not Found: " + imageURL + " " + e);
        }
        //Initiate the image load
        super.repaint();
    }  
    
    public void paint(Graphics g){
            try{
                //Load the image, set size of image to fit jPanel1
                g.drawImage(this.image, 0, 0,jPanel1.getWidth(), jPanel1.getHeight(), null);
                jPanel1.paintComponents(g);
                System.out.println("Image Setted");
        }catch(Exception e){
                e.printStackTrace();
        }
    }
}